package com.cqc.jdk8.Jutil.concurrent;

import org.junit.Test;

import java.util.concurrent.*;

/**
 * @author cui
 * @date 2025/3/22 14:12
 * @description
 **/
public class CallableTest {


    @Test
    public void f1() throws Exception {
        ExecutorService executorService = Executors.newCachedThreadPool();
        Future<String> future = executorService.submit(() -> {
            TimeUnit.SECONDS.sleep(3);
            System.out.println(" 子线程 threadId: " + Thread.currentThread().getId() + ",threadName: " + Thread.currentThread().getName());
            return "Callable f1";
        });

        //debug可以看到 submit()没有阻塞主线程，
        System.out.println(" 主线程 threadId: " + Thread.currentThread().getId() + ",threadName: " + Thread.currentThread().getName());
        //知道调用get()，才会执行callable.call()方法
        System.out.println(future.get());
    }

}
